using System.Linq;
using Android.Graphics;
using Android.Util;
using Android.Views;
using Android.Widget;
using mb.Droid;

namespace libmp
{
    class HistoryRecordView : ExMovieList
    {
        public MyFragment CreateFragment()
        {
            myFragment = new MyFragment()
            {
                Hold = 0,
                    MyOnCreateView = (f, container) =>
                    {
                        return CreateView();
                    },
                    MyOnReEnter = f =>
                    {
                        ReloadData();
                    }
            };
            return myFragment;
        }

        MyFragment myFragment;
        LinearLayout rootLayout;
        public HistoryRecordView()
        {
            ReloadData();
        }

        public View CreateView()
        {
            if (rootLayout != null) return rootLayout;

            LinearLayout layout = new LinearLayout(activity);
            layout.Orientation = Orientation.Vertical;
            layout.SetBackgroundColor(Util.MainBKColor);
            layout.FillParent();
            layout.AddView(CreateTitleBar());
            layout.AddView(new LinearLayout(activity) { LayoutParameters = new ViewGroup.LayoutParams(-1, 10) });

            Setup();
            Reload();

            layout.AddView(GetListView());
            return rootLayout = layout;
        }

        void ReloadData()
        {
            dataSource = User.me.SeenVideoList.Select(vid =>
            {
                return DataStore.store.GetVideoItemById(vid);
            }).ToList();
            dataSource.Reverse();

            if (adapter != null)
                Reload();
        }

        View CreateTitleBar()
        {
            return Common.CreateTitleBar(new Common.TitleBarOption()
            {
                Title = "历史记录",
            });
        }
    }
}